﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using nRoute.Components;
using nRoute.Mapping;
using nRoute.ViewModels;
using SimpleShell.Views;
using nRoute.Mapping;

namespace SimpleShell.ViewModels
{
    [DefineNavigationContent("Content/PageA", typeof(PageAView))]
    [MapViewModel(typeof(PageAView))]
    [ResourceMeta("Message", "Page A of A", typeof(IViewModelProvider))]
    public class PageAViewModel : NavigationViewModelBase
    {
        private string _message;
        private IDictionary<string, Object> _metadata;

        public PageAViewModel([ResolveResourceMetadata(typeof(IViewModelProvider), "SimpleShell.Views.PageAView")] IDictionary<string, Object> metadata)
        {
            _metadata = metadata;
            this.Message = Convert.ToString(_metadata["Message"]);

            SetupCommands();
        }

        public string Message
        {
            get { return _message; }
            set
            {
                if (_message != value)
                {
                    _message = value;
                    base.NotifyPropertyChanged(() => Message);
                }
            }
        }

        [ResolveResourceMetadata(typeof(IViewModelProvider), "SimpleShell.Views.PageAView")]
        public IDictionary<string, Object> Metadata { get; set; }

        protected override ParametersCollection OnSaveState()
        {
            var _state = new ParametersCollection();
            _state.Add("Message", this.Message);
            return _state;
        }

        protected override void OnRestoreState(ParametersCollection state)
        {
            if (state != null && state.ContainsKey("Message"))
            {
                this.Message = state.GetValueOrDefault<string>("Message");
            }
        }

        private void SetupCommands()
        {
        }
    }
}
